package com.googlecode.garbagecan.cxfstudy.compress;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.transport.common.gzip.GZIPInInterceptor;
import org.apache.cxf.transport.common.gzip.GZIPOutInterceptor;

public class MyClient {

	private static final String address = "http://localhost:9000/ws/compress/bigDataService";

	public static void main(String[] args) {
		JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();
		factoryBean.setAddress(address);
		factoryBean.setServiceClass(BigDataService.class);
		Object obj = factoryBean.create();
		
		Client client = ClientProxy.getClient(obj);
		Endpoint endpoint = client.getEndpoint();
		endpoint.getInInterceptors().add(new LoggingInInterceptor());
		endpoint.getOutInterceptors().add(new LoggingOutInterceptor());
		endpoint.getInInterceptors().add(new GZIPInInterceptor());
		endpoint.getOutInterceptors().add(new GZIPOutInterceptor());
		
		BigDataService service = (BigDataService) obj;
		
		String name = "my big data";
		int size = 1024 * 4;
		
		long start = System.currentTimeMillis();
		service.getBigData(name, size);
		long stop = System.currentTimeMillis();
		System.out.println("Time: " + (stop - start));
	}
}
